package leetcode.merge_intervals;

import java.util.Arrays;
import java.util.Comparator;

public class Lc435 {

    public int eraseOverlapIntervals(int[][] intervals) {

        Arrays.sort(intervals, ((o1, o2) -> o1[0] - o2[0]));
        int l = intervals[0][0];
        int r = intervals[0][1];
        int cnt = 0;
        for (int i = 1; i < intervals.length; i++) {
            if (r > intervals[i][0]) {
                cnt++;
                r = Math.min(r, intervals[i][1]);
            } else r = intervals[i][1];
        }
        return cnt;
    }


}
